package com.ccl.iot.publics;

import java.util.Map;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

import com.ccl.iot.App;

public class SPUtil {
	private Context context;
	private SharedPreferences sp;
	private Editor editor;
	private static SPUtil sputil;

	public SPUtil() {
		this.context = App.getContext();
		sp = this.context.getSharedPreferences("ICON", 0);
		editor = sp.edit();
	}
	
	public static void init(){
		sputil = new SPUtil();
	}

	public static SPUtil getInstance() {
		return sputil;
	}

	public void putBoolean(String key, Boolean value) {
		editor.putBoolean(key, value);
		editor.commit();
	}

	public boolean getBoolean(String key, Boolean defValue) {
		return sp.getBoolean(key, defValue);
	}

	public void putString(String key, String value) {
		if (key == null) {
			return;
		}
		editor.putString(key, value);
		editor.commit();
	}

	public String getString(String key, String defValue) {
		return sp.getString(key, defValue);
	}

	public void putInt(String key, int value) {
		editor.putInt(key, value);
		editor.commit();
	}

	public int getInt(String key, int defValue) {
		return sp.getInt(key, defValue);
	}

	public Map<String, ?> getAll() {
		return sp.getAll();
	}
}
